﻿using com.guojin.mj.net.message.game;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerHeadPage : EventManager
{
    public override void InformationSetting()
    {         
    }

    public RawImage headRawImg;
    public Image trusteeshipImg;
    public Image outlineImg;
    public GameObject select;
    public Image playerStateImg;
    public GameObject downTimeObj;
    public Text nameStr; 
    public Text totalScoreStr;
    //public Image readyImg;
    
    public   void DownloadHeadPhoto(string url)
    {
        DownloadHeadTexture(headRawImg.gameObject,url);
        StartCoroutine(CopyHeadRawImgToHeadTexture());
    }
    //开启协程等待下载完头像后赋值给headTexture,缓存到player类中
    IEnumerator CopyHeadRawImgToHeadTexture()
    {
        yield return new WaitUntil(() => headRawImg.texture != null);
        transform.GetComponent<Player>().headTexture = headRawImg.texture;
    }

    public void SetTrusteeShipImg(bool show)
    {
        if (show)
        {
            trusteeshipImg.gameObject.SetActive(true);
        }
        else
        {
            trusteeshipImg.gameObject.SetActive(false);
        }
    } 

    public void SetOutlineImg(bool show)
    {
        if (show)
        {
            outlineImg.gameObject.SetActive(true);
        }
        else
        {
            outlineImg.gameObject.SetActive(false);
        }
    }

    public void SetSelectImg(bool show)
    {
        if (show)
        {
            select.gameObject.SetActive(true);
            select.GetComponent<Select>().isSelect = true;
        }
        else
        {
            select.gameObject.SetActive(false);
            select.GetComponent<Select>().isSelect = false;
        }
    }

    public void SetPlayerStateImg(string playerState)
    {
        if (string.IsNullOrEmpty(playerState))
        {
            playerStateImg.sprite = null;
            playerStateImg.gameObject.SetActive(false);
        }
        else
        {
            playerStateImg.sprite = Resources.Load<Sprite>("BDUI/playerState/" + playerState);
            playerStateImg.gameObject.SetActive(true);
        }
    }

    public  void SetNameText(string name)
    {
        SetText(nameStr, name);
    }

    public   void SetTotalScoreText(int toatalScore)
    {
        SetText(totalScoreStr, toatalScore.ToString());
    }

    public void SetDownTime(bool show, int downTime)      
    {
        if (show)
        {
            downTimeObj.SetActive(true);
            downTimeObj.GetComponent<DownTimePage>().SetDownTime(downTime);
        }
        else
        {
            downTimeObj.SetActive(false);
        }
    }

    //public void SetReadyBtn(bool show)
    //{
    //    if (show)
    //    {
    //        readyImg.gameObject.SetActive(true);
    //    }
    //    else
    //    {
    //        readyImg.gameObject.SetActive(false);
    //    }
    //}

   
}
